function throttle(fn, gapTime) {
    if (gapTime == null || gapTime == undefined) {
      gapTime = 1500
    }
    let _lastTime = null
  
    // 返回新的函数
    return function() {
      let _nowTime = +new Date()
      if (_nowTime - _lastTime > gapTime || !_lastTime) {
        fn.apply(this, arguments) //将this和传递给原函数
        _lastTime = _nowTime
      }
    }
  }
  
  function debounce(fn, wait) {
    var timer = null;
    return function() {
      var context = this
      var args = arguments
      if (timer) {
        clearTimeout(timer);
        timer = null;
      }
      timer = setTimeout(function() {
        fn.apply(context, args)
      }, wait)
    }
  }
  
module.exports = {
throttle: throttle,
debounce: debounce
}